<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表白墙</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }
        .container {
            width: 400px;
            margin: 150px auto;
            border: solid 2px;
        }
        h1 {
            text-align: center;
            margin-bottom: 20px;
        }
        p {
            text-align: center;
            color: gray;
            line-height: 50px;
        }
        .row {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-bottom: 20px;
        }
        span {
            width: 60px;
            margin-bottom: 5px;
        }
        input {
            width: 180px;
            height: 25px;
        }
        .submit {
            width: 300px;
            height: 30px;
            background-color: orange;
            color: white;
            border: none;
            border-radius: 5px;
        }
        .submit:active {
            background-color: gray;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>表白墙</h1>
        <p>输入后点击提交，会将信息显示在表格中</p>
        <div>
            <div class="row">
                <span>谁：</span>
                <input type="text" class="edit">
            </div>
            <div class="row">
                <span>对谁：</span>
                <input type="text" class="edit">
            </div>
            <div class="row">
                <span>说：</span>
                <input type="text" class="edit">
            </div>
            <div class="row">
                <input type="button" value="提交" class="submit" onclick="submit()">
            </div>
        </div>
    </div>
    <script>
        function submit() {
            let edits = document.querySelectorAll('.edit');
            let from = edits[0].value
            let to = edits[1].value
            let message = edits[2].value
            if (from == '' || to == '' || message == '') {
                return;
            }
            let result = from + '对' + to + '说:' + message;
            let element = document.createElement('div')
            element.className = 'row'
            element.innerHTML = result
            let container = document.querySelector('.container')
            container.appendChild(element)
            for (let i = 0; i < 3; i++) {
                edits[i].value = ''
            }
        }
    </script>
</body>
</html>